<template>
    <div class="mod-demo-echarts">
        <el-row :gutter="20">
            <el-col :span="24">
                <el-card>
                <div id="J_chartLineBox_B" class="chart-box"></div>
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>
<script>
import echarts from 'echarts'
import { treeDataTranslate } from '@/utils'
export default {
    data(){
        return {
            key: [],
            value: [],
            chartLine: null
        }
    },
    mounted () {
      this.initChartLine()
    },
    activated () {
      if (this.chartLine) {
        this.chartLine.resize()
      }
    },
    methods: {
      activeItem(_item){
        this.titleList.forEach(item=>{
          item.active=false;
        });
        _item.active = true;
        console.log(this.titleList);
        this.$forceUpdate();
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/sku/getSkuInfo'),
          method: 'get',
          params: null
        }).then(({data}) => {
          this.key = data.sku.key,
          this.value = data.sku.value,
          this.dataListLoading = false,
          this.initChartLine(),
          console.info(data.sku.key)
        })
      },
      // 折线图
      initChartLine (dt) {
        var option = {
          'title': {
            'text': 'sku销售波动'
          },
          'tooltip': {
            'trigger': 'axis'
          },
          'legend': {
            'data': [ 'sku']
          },
          'grid': {
            'left': '3%',
            'right': '4%',
            'bottom': '3%',
            'containLabel': true
          },
          'toolbox': {
            'feature': {
              'saveAsImage': { }
            }
          },
          'xAxis': {
            'type': 'category',
            'boundaryGap': false,
            'data': this.key
          },
          'yAxis': {
            'type': 'value'
          },
          'series': [
            {
              'name': 'sku',
              'type': 'line',
              'stack': '总量',
              'data': this.value
            }
          ]
        }
        this.chartLine = echarts.init(document.getElementById('J_chartLineBox_B'))
        this.chartLine.setOption(option)
        window.addEventListener('resize', () => {
          this.chartLine.resize()
        })
      },
    },
    activated(){
        this.getDataList()
    }
}
</script>

<style lang="scss">
  .mod-demo-echarts {
    > .el-alert {
      margin-bottom: 10px;
    }
    > .el-row {
      margin-top: -10px;
      margin-bottom: -10px;
      .el-col {
        padding-top: 10px;
        padding-bottom: 10px;
      }
    }
    .chart-box {
      min-height: 400px;
    }
  }
</style>